package io.gitee.devaper.starlight.common.util

/*
    这里存放有关日期时间的工具
 */

import java.text.*
import java.time.*
import java.time.format.*
import java.util.*

const val DATE_PATTERN = "yyyy-MM-dd"
const val TIME_PATTERN = "HH:mm:ss"
const val DATETIME_PATTERN = "$DATE_PATTERN $TIME_PATTERN"

// region LocalDate

val localDateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern(DATE_PATTERN)

/**
 * 获取当前LocalDate UTC+8
 */
fun currentLocalDate() = LocalDate.now()

/**
 * 格式化当前LocalDate
 */
fun LocalDate.format(): String = localDateFormatter.format(this)

// endregion


// region LocalTime

val localTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern(TIME_PATTERN)

/**
 * 获取当前LocalTime UTC+8
 */
fun currentLocalTime() = LocalTime.now()

/**
 * 格式化当前LocalTime
 */
fun LocalTime.format(): String = localTimeFormatter.format(this)

// endregion



// region LocalDateTime

val localDateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern(DATETIME_PATTERN)

/** 获取当前LocalDateTime UTC+8 */
fun currentLocalDateTime() = LocalDateTime.now()

/**
 * 格式化当前LocalDateTime
 */
fun LocalDateTime.format(): String = localDateTimeFormatter.format(this)

// endregion



/**
 * 格式化当前日期
 */
fun Date.format(pattern: String = DATETIME_PATTERN): String = SimpleDateFormat(pattern).format(this)





